package com.lcg.weixin.web;

import com.alibaba.fastjson.JSON;
import com.lcg.weixin.entity.Page;
import com.lcg.weixin.entity.RandomNameUtils;
import com.lcg.weixin.entity.UserInfo;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;

/**
 * @author: LCG
 * @date: 2022-08-13 17:47:40
 * @description:
 **/

@RestController
@RequestMapping("/user")
public class ReactController {

    @RequestMapping("/userList")
    public Page getUserList(){

        Page page=new Page();
        page.setPageNo(new Random().nextInt(5));
        page.setPageSize(10);
        page.setTotal(new Random().nextInt(100));
        UserInfo userInfo=null;
        List<UserInfo> list=new ArrayList<>();
        for (int i = 0; i < new Random().nextInt(10); i++) {
             userInfo=new UserInfo();
            userInfo.setAge(new Random().nextInt(100));
            String randomName = RandomNameUtils.getRandomName();
            userInfo.setUserName(randomName);
            List<String> list11=new ArrayList<>();
            List<UserInfo> listUserInfo=new ArrayList<>();
            for (int j = 0; j < new Random().nextInt(8); j++) {
                String randomName1 = RandomNameUtils.getRandomName();
                list11.add(randomName1);
                UserInfo user=new UserInfo();
                user.setUserName( RandomNameUtils.getRandomName());
                listUserInfo.add(user);
            }
            userInfo.setListUsers(listUserInfo);
            userInfo.setList(list11);
            list.add(userInfo);
        }

        page.setResult(list);

       return page;
    }


    @RequestMapping("/add")
    public void test02(@RequestBody Map<String,Object> map){

        System.out.println(JSON.toJSONString(map));

    }

}
